import { VmoRequest } from "vmo-request";
// sk-eORZFTPzg6IyIbycyehA3DhtLAQtFB36898B5409011F0A10E12A7BDCC9A4B
import { Embedding } from "./tools/embedding";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter"
import { DashVector } from "./tools/dashVector";
import { readMarkdownFiles } from "./tools/readfies";
import path from "path"

const Eb = new Embedding("http://localhost:11434/api/embeddings")
const dashVectorDataBase = new DashVector(
  "vrs-cn-lf64ah2ur0002t.dashvector.cn-shanghai.aliyuncs.com",
  "sk-eORZFTPzg6IyIbycyehA3DhtLAQtFB36898B5409011F0A10E12A7BDCC9A4B"
)
export async function vec_search(){
  const query = "生物趣闻";
  const queryEmbedding = await Eb.embedding(query);
  const documents = await readMarkdownFiles(path.join(__dirname, 'articles'))  
  const collection = await dashVectorDataBase.stats('test');
  if(collection.data.code === -2021){
    await dashVectorDataBase.create({name:'test',dimension:1024})
  }else{
    const result = await dashVectorDataBase.query('test',{
      vector:queryEmbedding,
      // filter:"keyword not in ['动物']",
      sparse_vector:{"1":0.1,"1000":0.0},
      topk:5
    })
    console.log(query, result.data.output)
    // documents.forEach(async (text:string)=>{
    //   const queryEmbedding = await Eb.embedding(text)
    //   console.log(query,queryEmbedding)
    //   const m = await dashVectorDataBase.insert('test',[
    //     {vector:queryEmbedding,fields:{text}}
    //   ])
    // })
  }
}